package galaxy;

import irio.gamer.gamer;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import Logic.GalaxyComponent;

public class GalaxyComponentPanel extends JPanel{

	
	public static ComponentDetailPanel cp = null;;
	public static GalaxyComponentListPanel cpl = null;

	static public JPanel buttonPanel() {
		JPanel pnl = new JPanel();
		pnl.setLayout(new GridLayout(1,2));
		
		JButton btnCreate = new JButton("New");
		JButton btnDelete = new JButton("Delete");
		
		pnl.add(btnCreate);
		pnl.add(btnDelete);
		
		btnCreate.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {

				GalaxyComponent gc = new GalaxyComponent();
				gc.component_no = gamer.galaxy.components.size()+1;
				gamer.galaxy.components.add(gc);
				GalaxyComponentPanel.cpl.reload();
				gamer.imagePanel.preview.resetPreview(false);
				
			}
		});

		btnDelete.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {

				//gamer.galaxy.components.remove(GalaxyComponentPanel.cp.current);
				gamer.galaxy.RemoveComponent(GalaxyComponentPanel.cp.current);
				GalaxyComponentPanel.cpl.reload();
				gamer.imagePanel.preview.resetPreview(false);

			}
		});

		return pnl;
	}
	
	public GalaxyComponentPanel() {
		setLayout(new GridLayout(2,1));
		cp = new ComponentDetailPanel();
		cpl = new GalaxyComponentListPanel();
		add(cpl);
		add(cp);
	}
	
}
